home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Atari Compendium
/
The Atari Compendium (Toad Computers) (1994).iso
/
files
/
umich
/
tex
/
td187src.lzh
/
UNDO.I
< prev
next >
Wrap
Text File
|
1991-12-14
|
4KB
|
150 lines
IMPLEMENTATION MODULE Undo;
FROM Types IMPORT ObjectPtrTyp, DrawObjectTyp;
FROM SYSTEM IMPORT ADDRESS , ADR, WORD ;
FROM Storage IMPORT ALLOCATE , DEALLOCATE;
IMPORT MagicSys ;
IMPORT Variablen;
IMPORT CommonData;
VAR LastObject : ObjectPtrTyp;
CopyOfObjects : ObjectPtrTyp;
StoreRef : ObjectPtrTyp;
StoreRes : INTEGER;
UndoMode : BOOLEAN;
PROCEDURE SwapObjects;
VAR tmp : ObjectPtrTyp; itmp : INTEGER;
BEGIN
IF CopyOfObjects<>NIL THEN
itmp := CommonData.InternalResolution;
CommonData.InternalResolution := StoreRes;
StoreRes := itmp;
tmp := Variablen.FirstObject;
Variablen.FirstObject := CopyOfObjects;
CopyOfObjects := tmp;
tmp := Variablen.RefObject;
Variablen.RefObject := StoreRef;
StoreRef := tmp;
tmp := Variablen.FirstObject;
WHILE tmp^.Next<>NIL DO
tmp := tmp^.Next;
END;
Variablen.LastObject := tmp;
END;
END SwapObjects;
PROCEDURE DeleteCopy;
PROCEDURE DeleteTree(start : ObjectPtrTyp);
VAR tmp1, tmp2 : ObjectPtrTyp;
BEGIN
tmp1 := start;
WHILE tmp1<>NIL DO
tmp2 := tmp1^.Next;
IF (ORD(tmp1^.Code [ 0 ]) = ORD(Picture)) AND
(tmp1^.Children<>NIL) THEN
DeleteTree(tmp1^.Children);
END;
IF (tmp1^.CPtr<>NIL) AND (tmp1^.Code [ 9 ] > 0) THEN
DEALLOCATE (tmp1^.CPtr , MagicSys.CastToLCard (tmp1^.Code [ 9 ])) ;
END;
IF (tmp1^.EPtr<>NIL) AND (tmp1^.Code [ 3 ] > 0) THEN
DEALLOCATE (tmp1^.EPtr , 4 * MagicSys.CastToLCard (tmp1^.Code [ 3 ])) ;
END;
DISPOSE (tmp1) ;
tmp1 := tmp2;
END;
END DeleteTree;
BEGIN
IF CopyOfObjects<>NIL THEN
DeleteTree(CopyOfObjects);
END;
CopyOfObjects := NIL;
StoreRef := NIL;
END DeleteCopy;
PROCEDURE DuplicateObjects;
PROCEDURE DuplicateTree(treestart, copystart : ObjectPtrTyp);
VAR tmp1, tmp2 : ObjectPtrTyp; i : INTEGER;
BEGIN
tmp1 := copystart;
tmp2 := treestart;
REPEAT
IF tmp2=Variablen.RefObject THEN
StoreRef := tmp1;
END;
tmp1^ := tmp2^;
tmp1^.CPtr := NIL;
tmp1^.EPtr := NIL;
tmp1^.Next := NIL;
tmp1^.Children := NIL;
IF (ORD(tmp2^.Code [ 0 ]) = ORD(Picture)) AND
(tmp2^.Children<>NIL) THEN
NEW(tmp1^.Children);
DuplicateTree(tmp2^.Children, tmp1^.Children);
END;
IF (tmp2^.CPtr<>NIL) AND (tmp2^.Code [ 9 ] > 0) THEN
ALLOCATE (tmp1^.CPtr , MagicSys.CastToLCard (tmp1^.Code [ 9 ])) ;
FOR i:=0 TO tmp1^.Code [ 9 ] - 1 DO
tmp1^.CPtr^[i] := tmp2^.CPtr^[i];
END;
END;
IF (tmp2^.EPtr<>NIL) AND (tmp2^.Code [ 3 ] > 0) THEN
ALLOCATE (tmp1^.EPtr , 4 * MagicSys.CastToLCard (tmp2^.Code [ 3 ])) ;
FOR i := 0 TO tmp2^.Code [ 3 ] - 1 DO
tmp1^.EPtr^[ (2 * i) ] := tmp2^.EPtr^ [ (2 * i) ] ;
tmp1^.EPtr^[ (2 * i) + 1] := tmp2^.EPtr^ [ (2 * i) + 1 ] ;
END;
END;
IF tmp2^.Next<>NIL THEN
NEW(tmp1^.Next);
END;
tmp2 := tmp2^.Next;
tmp1 := tmp1^.Next;
UNTIL tmp2=NIL;
END DuplicateTree;
BEGIN
NEW(CopyOfObjects);
StoreRes := CommonData.InternalResolution;
StoreRef := NIL;
DuplicateTree(Variablen.FirstObject, CopyOfObjects);
END DuplicateObjects;
PROCEDURE PrepareUndo(prepUndo : BOOLEAN);
BEGIN
IF UndoMode THEN
DeleteCopy;
IF prepUndo THEN
DuplicateObjects;
END;
END;
END PrepareUndo;
PROCEDURE UndoIt();
BEGIN
IF UndoMode THEN
SwapObjects;
END;
END UndoIt;
PROCEDURE SetUndoFeature(On : BOOLEAN);
BEGIN
UndoMode := On;
IF NOT UndoMode THEN
DeleteCopy;
END;
END SetUndoFeature;
BEGIN
LastObject := NIL;
CopyOfObjects := NIL;
UndoMode := TRUE;
END Undo.